﻿namespace STT.Parser
{
    using System.Drawing;
    using System.Text.RegularExpressions;
    using System.Windows.Forms;

    public static class Highlight
    {
        public static class C
        {
            private static Regex regex_reserved_words = new Regex("(typedef |struct |union |enum )");
            private static Regex regex_comment1 = new Regex(@"((/\*)[^/]*(\*/))|(/{2}.*$)", RegexOptions.Multiline);
            private static Regex regex_padding = new Regex(@"(UINT8) +(_PADDING)[0-9]*(_\[).*(\];)");

            public static void ColorRichTextBox(RichTextBox rich_text_box)
            {
                MatchCollection matchs = regex_reserved_words.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match in matchs)
                    {
                        rich_text_box.Select(match.Index, match.Length);
                        rich_text_box.SelectionColor = Color.Blue;
                    }
                }
                matchs = regex_padding.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match2 in matchs)
                    {
                        rich_text_box.Select(match2.Index, match2.Length);
                        rich_text_box.SelectionColor = Color.Red;
                    }
                }
                matchs = regex_comment1.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match3 in matchs)
                    {
                        rich_text_box.Select(match3.Index, match3.Length);
                        rich_text_box.SelectionColor = Color.Green;
                    }
                }
                rich_text_box.Select(0, 0);
            }
        }

        public static class IDA
        {
            private static Regex regex_reserved_words = new Regex("(AddStrucEx|SetStrucComment|AddStrucMember|GetStrucSize|GetStrucIdByName| if |AddConstEx|SetConstCmt|GetConstEx|AddEnum|FF_BYTE|FF_WORD|FF_DWRD|FF_QWRD|FF_OWRD|FF_STRU|FF_0NUMD|FF_1NUMD)");
            private static Regex regex_comment = new Regex(@"((/\*)[^/]*(\*/))|(/{2}.*$)", RegexOptions.Multiline);
            private static Regex regex_string = new Regex("\".*\"", RegexOptions.Multiline);

            public static void ColorRichTextBox(RichTextBox rich_text_box)
            {
                MatchCollection matchs = regex_reserved_words.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match in matchs)
                    {
                        rich_text_box.Select(match.Index, match.Length);
                        rich_text_box.SelectionColor = Color.Blue;
                    }
                }
                matchs = regex_string.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match2 in matchs)
                    {
                        rich_text_box.Select(match2.Index, match2.Length);
                        rich_text_box.SelectionColor = Color.Maroon;
                    }
                }
                matchs = regex_comment.Matches(rich_text_box.Text);
                if (matchs.Count > 0)
                {
                    foreach (Match match3 in matchs)
                    {
                        rich_text_box.Select(match3.Index, match3.Length);
                        rich_text_box.SelectionColor = Color.Green;
                    }
                }
                rich_text_box.Select(0, 0);
            }
        }
    }
}